package com.devicemantra.coordinate.interfaces.sms;

import java.net.HttpURLConnection;

import com.devicemantra.coordinate.interfaces.http.CHttpPost;
import com.devicemantra.coordinate.util.CXMLBuilder;
import com.google.appengine.repackaged.com.google.common.util.Base64;


/* TODO: Add exception handling code - throw exceptions etc */
public class SMSFactory 
{
		
	public static SMS creatNewSMS()
	{
		SMS mSMSObj = new CSMS();
		return mSMSObj;
	}
	
	public static int sendSMS(SMS pSMSObj)
	{
		String lXmlStr = getSmsInXml(pSMSObj);
		System.out.println("Sending messages in XML :" + lXmlStr);
		CHttpPost lHttpPoster = new CHttpPost();
		lHttpPoster.send(lXmlStr);
		
		return 1;
	}
	
	public static String getUserName()
	{
		return "simith@smartcall.ae";
		//return "test@smartcall.ae";
		//return "Simith";
	}
	
	public static String getPassword()
	{
		//return "test";
		return "sim10";
	}
	
	public static String getSmsInXml(SMS pSMSObj)
	{
		CXMLBuilder lXmlBuilder = new CXMLBuilder();
		lXmlBuilder.AddOpeningTag("SMS");
		lXmlBuilder.AddCRLF();
		lXmlBuilder.AddNode("MobileNumber", pSMSObj.getMobileNumber());
		lXmlBuilder.AddNode("Message", pSMSObj.getMessage());
		lXmlBuilder.AddNode("Unicode", Integer.toString(pSMSObj.getLanguage()));
		lXmlBuilder.AddNode("CampaignID", pSMSObj.getCampaingId());
		lXmlBuilder.AddNode("UserID", getUserName());
		lXmlBuilder.AddNode("Pwd",getPassword()); 
		lXmlBuilder.AddClosingTag("SMS");
		
		return lXmlBuilder.getXml();
	}
	
	


}
